<?php
use common\components\helpers\Util;
use yii\helpers\Html;
use common\components\extenders\MenuManage;
use doumiaoduo\layer\LayerAsset;
?>
<div class="docs-main">
    <input type="hidden" id="student" value="<?=$student->name?>">
    <table id="tablesaw" class="tablesaw table yx-table1 yx-table5 table-striped with-check"  >
        <tr class="yx-bgd2f6ec">
            <td>课程名称</td>
            <td>上课日期</td>
            <td>上课时间</td>
            <td>课次</td>
            <td>操作</td>
        </tr>
        <?php foreach ($data as $i => $v):?>
            <tr>
                <td><?=Html::encode($v->title)?></td>
                <td><?=date('Y-m-d',$v->class_date)?></td>
                <td><?=Util::getTime($v->start_time).'-'.Util::getTime($v->end_time)?></td>
                <td><?=Html::encode($v->lesson)?></td>
                <td>
                    <?=(new MenuManage(MenuManage::TOP_MENU))->detailsMenu('newclassmanage','unlimitedsign',false,['class' => 'signin btn yx-radius2 yx-d-card yx-bg94d5a2','data'=>['id'=>$id,'lesson_id'=>$v->lesson_id]]);?>
                </td>
            </tr>
        <?php endforeach; ?>
    </table>
    <?php ?>
    <div id="return" style="position: absolute;z-index: -1000; left: 10px; top: 10px;"></div>
</div>
<?php
LayerAsset::register($this);
$js=<<<JS
    layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });
    $(document).on('click','.signin',function(){
        var _this = $(this);
        var url = _this.data('url');
        var day = _this.parents('tr').find('td').eq(1).html();
        var lesson_id = _this.data('lesson_id');
        var name = $('#student').val();
         layer.confirm("确定给"+name+"打"+day+"的卡么？", {
            title: '打卡',
            area: ['440px', '270px'],
            skin: 'layui-confirm-customskin',
            shift:1,
            id:'layer-iframe',
            btn: ['确定','取消'],
            yes: function(index, layero){
                 $.ajax({
                    url:url,
                    type:'get',
                    data:{lesson_id:lesson_id},
                    dataType:'json',
                    _csrf:yii.getCsrfToken(),
                    success:function(data){
                        if(data.status == 1){
                            layer.msg("打卡成功！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            $('#return').html(data.str);
                            _this.parent().html('');
                            $("#return").jqprint(); 
                            $("#return").html('');
                        }else{
                            layer.msg("打卡失败！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
                            return false;
                        }
                    }

                });
              layer.close(index);
            }
         });
        return false;
    });

JS;
\Yii::$app->view->registerJs($js);
?>